package com.ruoyi.admin.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.admin.domain.CorpCompanies;
import com.ruoyi.admin.service.ICorpCompaniesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 宝企通-企业管理后台-合作企业Controller
 * 
 * @author Jimmy
 * @date 2022-08-01
 */
@RestController
@RequestMapping("/admin/corp_companies")
public class CorpCompaniesController extends BaseController
{
    @Autowired
    private ICorpCompaniesService corpCompaniesService;

    /**
     * 查询宝企通-企业管理后台-合作企业列表
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_companies:list')")
    @GetMapping("/list")
    public TableDataInfo list(CorpCompanies corpCompanies)
    {
        startPage();
        List<CorpCompanies> list = corpCompaniesService.selectCorpCompaniesList(corpCompanies);
        return getDataTable(list);
    }

    /**
     * 导出宝企通-企业管理后台-合作企业列表
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_companies:export')")
    @Log(title = "宝企通-企业管理后台-合作企业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CorpCompanies corpCompanies)
    {
        List<CorpCompanies> list = corpCompaniesService.selectCorpCompaniesList(corpCompanies);
        ExcelUtil<CorpCompanies> util = new ExcelUtil<CorpCompanies>(CorpCompanies.class);
        util.exportExcel(response, list, "宝企通-企业管理后台-合作企业数据");
    }

    /**
     * 获取宝企通-企业管理后台-合作企业详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_companies:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(corpCompaniesService.selectCorpCompaniesById(id));
    }

    /**
     * 新增宝企通-企业管理后台-合作企业
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_companies:add')")
    @Log(title = "宝企通-企业管理后台-合作企业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CorpCompanies corpCompanies)
    {
        return toAjax(corpCompaniesService.insertCorpCompanies(corpCompanies));
    }

    /**
     * 修改宝企通-企业管理后台-合作企业
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_companies:edit')")
    @Log(title = "宝企通-企业管理后台-合作企业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CorpCompanies corpCompanies)
    {
        return toAjax(corpCompaniesService.updateCorpCompanies(corpCompanies));
    }

    /**
     * 删除宝企通-企业管理后台-合作企业
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_companies:remove')")
    @Log(title = "宝企通-企业管理后台-合作企业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(corpCompaniesService.deleteCorpCompaniesByIds(ids));
    }
}
